package androidx.media;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.service.media.MediaBrowserService;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.MediaSessionCompat.Token;
import android.support.v4.os.ResultReceiver;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import o.ds;
import o.fh;
import o.he;
import o.ln;
import o.lo;
import o.lq;
import o.lr;
import o.u;

public abstract class MediaBrowserServiceCompat extends Service {
    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY})
    public static final String KEY_MEDIA_ITEM = "media_item";
    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY})
    public static final String KEY_SEARCH_RESULTS = "search_results";
    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY})
    public static final int RESULT_ERROR = -1;
    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY})
    public static final int RESULT_OK = 0;
    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY})
    public static final int RESULT_PROGRESS_UPDATE = 1;
    public static final String SERVICE_INTERFACE = "android.media.browse.MediaBrowserService";
    static final boolean ˏ = Log.isLoggable("MBServiceCompat", 3);
    final ds<IBinder, d> ˊ = new ds();
    d ˋ;
    Token ˎ;
    final ServiceHandler ॱ = new ServiceHandler(this);
    private e ᐝ;

    public static class h<T> {
        private int ˊ;
        private final Object ˋ;
        private boolean ˎ;
        private boolean ˏ;
        private boolean ॱ;

        h(Object obj) {
            this.ˋ = obj;
        }

        public void ˋ(T t) {
            if (this.ˎ || this.ˏ) {
                throw new IllegalStateException("sendResult() called when either sendResult() or sendError() had already been called for: " + this.ˋ);
            }
            this.ˎ = true;
            ॱ((Object) t);
        }

        public void ˋ(Bundle bundle) {
            if (this.ˎ || this.ˏ) {
                throw new IllegalStateException("sendError() called when either sendResult() or sendError() had already been called for: " + this.ˋ);
            }
            this.ˏ = true;
            ॱ(bundle);
        }

        boolean ॱ() {
            return this.ॱ || this.ˎ || this.ˏ;
        }

        void ˊ(int i) {
            this.ˊ = i;
        }

        int ˎ() {
            return this.ˊ;
        }

        void ॱ(T t) {
        }

        void ॱ(Bundle bundle) {
            throw new UnsupportedOperationException("It is not supported to send an error for " + this.ˋ);
        }
    }

    final class ServiceHandler extends Handler {
        private final i ˊ = new i(this.ˋ);
        final /* synthetic */ MediaBrowserServiceCompat ˋ;

        ServiceHandler(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
            this.ˋ = mediaBrowserServiceCompat;
        }

        public void handleMessage(Message message) {
            Bundle data = message.getData();
            Bundle bundle;
            switch (message.what) {
                case 1:
                    Bundle bundle2 = data.getBundle("data_root_hints");
                    MediaSessionCompat.ˏ(bundle2);
                    this.ˊ.ˊ(data.getString("data_package_name"), data.getInt("data_calling_pid"), data.getInt("data_calling_uid"), bundle2, new n(message.replyTo));
                    return;
                case 2:
                    this.ˊ.ॱ(new n(message.replyTo));
                    return;
                case 3:
                    Bundle bundle3 = data.getBundle("data_options");
                    MediaSessionCompat.ˏ(bundle3);
                    this.ˊ.ˊ(data.getString("data_media_item_id"), fh.ˏ(data, "data_callback_token"), bundle3, new n(message.replyTo));
                    return;
                case 4:
                    this.ˊ.ॱ(data.getString("data_media_item_id"), fh.ˏ(data, "data_callback_token"), new n(message.replyTo));
                    return;
                case 5:
                    this.ˊ.ॱ(data.getString("data_media_item_id"), (ResultReceiver) data.getParcelable("data_result_receiver"), new n(message.replyTo));
                    return;
                case 6:
                    Bundle bundle4 = data.getBundle("data_root_hints");
                    MediaSessionCompat.ˏ(bundle4);
                    this.ˊ.ˎ(new n(message.replyTo), data.getString("data_package_name"), data.getInt("data_calling_pid"), data.getInt("data_calling_uid"), bundle4);
                    return;
                case 7:
                    this.ˊ.ˋ(new n(message.replyTo));
                    return;
                case 8:
                    bundle = data.getBundle("data_search_extras");
                    MediaSessionCompat.ˏ(bundle);
                    this.ˊ.ˏ(data.getString("data_search_query"), bundle, (ResultReceiver) data.getParcelable("data_result_receiver"), new n(message.replyTo));
                    return;
                case 9:
                    bundle = data.getBundle("data_custom_action_extras");
                    MediaSessionCompat.ˏ(bundle);
                    this.ˊ.ॱ(data.getString("data_custom_action"), bundle, (ResultReceiver) data.getParcelable("data_result_receiver"), new n(message.replyTo));
                    return;
                default:
                    Log.w("MBServiceCompat", "Unhandled message: " + message + "\n  Service version: " + 2 + "\n  Client version: " + message.arg1);
                    return;
            }
        }

        public boolean sendMessageAtTime(Message message, long j) {
            Bundle data = message.getData();
            data.setClassLoader(MediaBrowserCompat.class.getClassLoader());
            data.putInt("data_calling_uid", Binder.getCallingUid());
            data.putInt("data_calling_pid", Binder.getCallingPid());
            return super.sendMessageAtTime(message, j);
        }

        public void ˊ(Runnable runnable) {
            if (Thread.currentThread() == getLooper().getThread()) {
                runnable.run();
            } else {
                post(runnable);
            }
        }
    }

    public static final class a {
        private final String ˊ;
        private final Bundle ˏ;

        public String ॱ() {
            return this.ˊ;
        }

        public Bundle ˎ() {
            return this.ˏ;
        }
    }

    interface e {
        Bundle ˊ();

        void ˋ(Token token);

        void ˋ(String str, Bundle bundle);

        void ˎ();

        IBinder ˏ(Intent intent);

        void ˏ(o.lp.d dVar, String str, Bundle bundle);

        o.lp.d ॱ();
    }

    @RequiresApi(21)
    class b implements e, o.lr.d {
        final List<Bundle> ˊ = new ArrayList();
        Object ˎ;
        final /* synthetic */ MediaBrowserServiceCompat ˏ;
        Messenger ॱ;

        b(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
            this.ˏ = mediaBrowserServiceCompat;
        }

        public void ˎ() {
            this.ˎ = lr.ˋ(this.ˏ, this);
            lr.ˎ(this.ˎ);
        }

        public IBinder ˏ(Intent intent) {
            return lr.ˎ(this.ˎ, intent);
        }

        public void ˋ(final Token token) {
            this.ˏ.ॱ.ˊ(new Runnable(this) {
                final /* synthetic */ b ˏ;

                public void run() {
                    if (!this.ˏ.ˊ.isEmpty()) {
                        u ˎ = token.ˎ();
                        if (ˎ != null) {
                            for (Bundle ˏ : this.ˏ.ˊ) {
                                fh.ˏ(ˏ, "extra_session_binder", ˎ.asBinder());
                            }
                        }
                        this.ˏ.ˊ.clear();
                    }
                    lr.ˊ(this.ˏ.ˎ, token.ॱ());
                }
            });
        }

        public void ˋ(String str, Bundle bundle) {
            ˏ(str, bundle);
            ˊ(str, bundle);
        }

        public void ˏ(o.lp.d dVar, String str, Bundle bundle) {
            ॱ(dVar, str, bundle);
        }

        public o.lr.c ˋ(String str, int i, Bundle bundle) {
            Bundle bundle2;
            if (bundle == null || bundle.getInt("extra_client_version", 0) == 0) {
                bundle2 = null;
            } else {
                bundle.remove("extra_client_version");
                this.ॱ = new Messenger(this.ˏ.ॱ);
                Bundle bundle3 = new Bundle();
                bundle3.putInt("extra_service_version", 2);
                fh.ˏ(bundle3, "extra_messenger", this.ॱ.getBinder());
                if (this.ˏ.ˎ != null) {
                    IBinder iBinder;
                    u ˎ = this.ˏ.ˎ.ˎ();
                    String str2 = "extra_session_binder";
                    if (ˎ == null) {
                        iBinder = null;
                    } else {
                        iBinder = ˎ.asBinder();
                    }
                    fh.ˏ(bundle3, str2, iBinder);
                    bundle2 = bundle3;
                } else {
                    this.ˊ.add(bundle3);
                    bundle2 = bundle3;
                }
            }
            this.ˏ.ˋ = new d(this.ˏ, str, -1, i, bundle, null);
            a onGetRoot = this.ˏ.onGetRoot(str, i, bundle);
            this.ˏ.ˋ = null;
            if (onGetRoot == null) {
                return null;
            }
            if (bundle2 == null) {
                bundle2 = onGetRoot.ˎ();
            } else if (onGetRoot.ˎ() != null) {
                bundle2.putAll(onGetRoot.ˎ());
            }
            return new o.lr.c(onGetRoot.ॱ(), bundle2);
        }

        public void ˎ(String str, final o.lr.e<List<Parcel>> eVar) {
            this.ˏ.onLoadChildren(str, new h<List<MediaItem>>(this, str) {
                final /* synthetic */ b ˋ;

                /* synthetic */ void ॱ(Object obj) {
                    ˎ((List) obj);
                }

                void ˎ(List<MediaItem> list) {
                    Object obj = null;
                    if (list != null) {
                        List arrayList = new ArrayList();
                        for (MediaItem mediaItem : list) {
                            Parcel obtain = Parcel.obtain();
                            mediaItem.writeToParcel(obtain, 0);
                            arrayList.add(obtain);
                        }
                        obj = arrayList;
                    }
                    eVar.ˋ(obj);
                }
            });
        }

        void ˏ(String str, Bundle bundle) {
            lr.ˏ(this.ˎ, str);
        }

        void ˊ(final String str, final Bundle bundle) {
            this.ˏ.ॱ.post(new Runnable(this) {
                final /* synthetic */ b ˋ;

                public void run() {
                    for (IBinder iBinder : this.ˋ.ˏ.ˊ.keySet()) {
                        this.ˋ.ˎ((d) this.ˋ.ˏ.ˊ.get(iBinder), str, bundle);
                    }
                }
            });
        }

        void ॱ(final o.lp.d dVar, final String str, final Bundle bundle) {
            this.ˏ.ॱ.post(new Runnable(this) {
                final /* synthetic */ b ˊ;

                public void run() {
                    for (int i = 0; i < this.ˊ.ˏ.ˊ.size(); i++) {
                        d dVar = (d) this.ˊ.ˏ.ˊ.ˋ(i);
                        if (dVar.ॱ.equals(dVar)) {
                            this.ˊ.ˎ(dVar, str, bundle);
                        }
                    }
                }
            });
        }

        void ˎ(d dVar, String str, Bundle bundle) {
            List<he> list = (List) dVar.ʻ.get(str);
            if (list != null) {
                for (he heVar : list) {
                    if (ln.ˊ(bundle, (Bundle) heVar.ˏ)) {
                        this.ˏ.ˊ(str, dVar, (Bundle) heVar.ˏ, bundle);
                    }
                }
            }
        }

        public Bundle ˊ() {
            if (this.ॱ == null) {
                return null;
            }
            if (this.ˏ.ˋ == null) {
                throw new IllegalStateException("This should be called inside of onGetRoot, onLoadChildren, onLoadItem, onSearch, or onCustomAction methods");
            } else if (this.ˏ.ˋ.ˋ != null) {
                return new Bundle(this.ˏ.ˋ.ˋ);
            } else {
                return null;
            }
        }

        public o.lp.d ॱ() {
            if (this.ˏ.ˋ != null) {
                return this.ˏ.ˋ.ॱ;
            }
            throw new IllegalStateException("This should be called inside of onGetRoot, onLoadChildren, onLoadItem, onSearch, or onCustomAction methods");
        }
    }

    @RequiresApi(23)
    class c extends b implements o.lo.b {
        final /* synthetic */ MediaBrowserServiceCompat ˋ;

        c(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
            this.ˋ = mediaBrowserServiceCompat;
            super(mediaBrowserServiceCompat);
        }

        public void ˎ() {
            this.ˎ = lo.ˎ(this.ˋ, this);
            lr.ˎ(this.ˎ);
        }

        public void ˋ(String str, final o.lr.e<Parcel> eVar) {
            this.ˋ.onLoadItem(str, new h<MediaItem>(this, str) {
                final /* synthetic */ c ˏ;

                /* synthetic */ void ॱ(Object obj) {
                    ˎ((MediaItem) obj);
                }

                void ˎ(MediaItem mediaItem) {
                    if (mediaItem == null) {
                        eVar.ˋ(null);
                        return;
                    }
                    Parcel obtain = Parcel.obtain();
                    mediaItem.writeToParcel(obtain, 0);
                    eVar.ˋ(obtain);
                }
            });
        }
    }

    class d implements DeathRecipient {
        public final HashMap<String, List<he<IBinder, Bundle>>> ʻ = new HashMap();
        public a ʼ;
        public final int ˊ;
        public final Bundle ˋ;
        public final String ˎ;
        public final int ˏ;
        public final o.lp.d ॱ;
        public final m ॱॱ;
        final /* synthetic */ MediaBrowserServiceCompat ᐝ;

        d(MediaBrowserServiceCompat mediaBrowserServiceCompat, String str, int i, int i2, Bundle bundle, m mVar) {
            this.ᐝ = mediaBrowserServiceCompat;
            this.ˎ = str;
            this.ˏ = i;
            this.ˊ = i2;
            this.ॱ = new o.lp.d(str, i, i2);
            this.ˋ = bundle;
            this.ॱॱ = mVar;
        }

        public void binderDied() {
            this.ᐝ.ॱ.post(new Runnable(this) {
                final /* synthetic */ d ॱ;

                {
                    this.ॱ = r1;
                }

                public void run() {
                    this.ॱ.ᐝ.ˊ.remove(this.ॱ.ॱॱ.ॱ());
                }
            });
        }
    }

    class f implements e {
        final /* synthetic */ MediaBrowserServiceCompat ˋ;
        private Messenger ॱ;

        f(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
            this.ˋ = mediaBrowserServiceCompat;
        }

        public void ˎ() {
            this.ॱ = new Messenger(this.ˋ.ॱ);
        }

        public IBinder ˏ(Intent intent) {
            if (MediaBrowserServiceCompat.SERVICE_INTERFACE.equals(intent.getAction())) {
                return this.ॱ.getBinder();
            }
            return null;
        }

        public void ˋ(final Token token) {
            this.ˋ.ॱ.post(new Runnable(this) {
                final /* synthetic */ f ˋ;

                public void run() {
                    Iterator it = this.ˋ.ˋ.ˊ.values().iterator();
                    while (it.hasNext()) {
                        d dVar = (d) it.next();
                        try {
                            dVar.ॱॱ.ˎ(dVar.ʼ.ॱ(), token, dVar.ʼ.ˎ());
                        } catch (RemoteException e) {
                            Log.w("MBServiceCompat", "Connection for " + dVar.ˎ + " is no longer valid.");
                            it.remove();
                        }
                    }
                }
            });
        }

        public void ˋ(@NonNull final String str, final Bundle bundle) {
            this.ˋ.ॱ.post(new Runnable(this) {
                final /* synthetic */ f ॱ;

                public void run() {
                    for (IBinder iBinder : this.ॱ.ˋ.ˊ.keySet()) {
                        this.ॱ.ॱ((d) this.ॱ.ˋ.ˊ.get(iBinder), str, bundle);
                    }
                }
            });
        }

        public void ˏ(@NonNull final o.lp.d dVar, @NonNull final String str, final Bundle bundle) {
            this.ˋ.ॱ.post(new Runnable(this) {
                final /* synthetic */ f ˋ;

                public void run() {
                    for (int i = 0; i < this.ˋ.ˋ.ˊ.size(); i++) {
                        d dVar = (d) this.ˋ.ˋ.ˊ.ˋ(i);
                        if (dVar.ॱ.equals(dVar)) {
                            this.ˋ.ॱ(dVar, str, bundle);
                            return;
                        }
                    }
                }
            });
        }

        void ॱ(d dVar, String str, Bundle bundle) {
            List<he> list = (List) dVar.ʻ.get(str);
            if (list != null) {
                for (he heVar : list) {
                    if (ln.ˊ(bundle, (Bundle) heVar.ˏ)) {
                        this.ˋ.ˊ(str, dVar, (Bundle) heVar.ˏ, bundle);
                    }
                }
            }
        }

        public Bundle ˊ() {
            if (this.ˋ.ˋ != null) {
                return this.ˋ.ˋ.ˋ == null ? null : new Bundle(this.ˋ.ˋ.ˋ);
            } else {
                throw new IllegalStateException("This should be called inside of onLoadChildren, onLoadItem, onSearch, or onCustomAction methods");
            }
        }

        public o.lp.d ॱ() {
            if (this.ˋ.ˋ != null) {
                return this.ˋ.ˋ.ॱ;
            }
            throw new IllegalStateException("This should be called inside of onLoadChildren, onLoadItem, onSearch, or onCustomAction methods");
        }
    }

    @RequiresApi(26)
    class g extends c implements o.lq.d {
        final /* synthetic */ MediaBrowserServiceCompat ʽ;

        g(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
            this.ʽ = mediaBrowserServiceCompat;
            super(mediaBrowserServiceCompat);
        }

        public void ˎ() {
            this.ˎ = lq.ˊ(this.ʽ, this);
            lr.ˎ(this.ˎ);
        }

        public void ˎ(String str, final o.lq.c cVar, Bundle bundle) {
            this.ʽ.onLoadChildren(str, new h<List<MediaItem>>(this, str) {
                final /* synthetic */ g ˊ;

                /* synthetic */ void ॱ(Object obj) {
                    ˎ((List) obj);
                }

                void ˎ(List<MediaItem> list) {
                    List list2 = null;
                    if (list != null) {
                        List arrayList = new ArrayList();
                        for (MediaItem mediaItem : list) {
                            Parcel obtain = Parcel.obtain();
                            mediaItem.writeToParcel(obtain, 0);
                            arrayList.add(obtain);
                        }
                        list2 = arrayList;
                    }
                    cVar.ˊ(list2, ˎ());
                }
            }, bundle);
        }

        public Bundle ˊ() {
            if (this.ʽ.ˋ != null) {
                return this.ʽ.ˋ.ˋ == null ? null : new Bundle(this.ʽ.ˋ.ˋ);
            } else {
                return lq.ˊ(this.ˎ);
            }
        }

        void ˏ(String str, Bundle bundle) {
            if (bundle != null) {
                lq.ˎ(this.ˎ, str, bundle);
            } else {
                super.ˏ(str, bundle);
            }
        }
    }

    class i {
        final /* synthetic */ MediaBrowserServiceCompat ˋ;

        i(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
            this.ˋ = mediaBrowserServiceCompat;
        }

        public void ˊ(String str, int i, int i2, Bundle bundle, m mVar) {
            if (this.ˋ.ˋ(str, i2)) {
                final m mVar2 = mVar;
                final String str2 = str;
                final int i3 = i;
                final int i4 = i2;
                final Bundle bundle2 = bundle;
                this.ˋ.ॱ.ˊ(new Runnable(this) {
                    final /* synthetic */ i ʽ;

                    public void run() {
                        IBinder ॱ = mVar2.ॱ();
                        this.ʽ.ˋ.ˊ.remove(ॱ);
                        d dVar = new d(this.ʽ.ˋ, str2, i3, i4, bundle2, mVar2);
                        this.ʽ.ˋ.ˋ = dVar;
                        dVar.ʼ = this.ʽ.ˋ.onGetRoot(str2, i4, bundle2);
                        this.ʽ.ˋ.ˋ = null;
                        if (dVar.ʼ == null) {
                            Log.i("MBServiceCompat", "No root for client " + str2 + " from service " + getClass().getName());
                            try {
                                mVar2.ˏ();
                                return;
                            } catch (RemoteException e) {
                                Log.w("MBServiceCompat", "Calling onConnectFailed() failed. Ignoring. pkg=" + str2);
                                return;
                            }
                        }
                        try {
                            this.ʽ.ˋ.ˊ.put(ॱ, dVar);
                            ॱ.linkToDeath(dVar, 0);
                            if (this.ʽ.ˋ.ˎ != null) {
                                mVar2.ˎ(dVar.ʼ.ॱ(), this.ʽ.ˋ.ˎ, dVar.ʼ.ˎ());
                            }
                        } catch (RemoteException e2) {
                            Log.w("MBServiceCompat", "Calling onConnect() failed. Dropping client. pkg=" + str2);
                            this.ʽ.ˋ.ˊ.remove(ॱ);
                        }
                    }
                });
                return;
            }
            throw new IllegalArgumentException("Package/uid mismatch: uid=" + i2 + " package=" + str);
        }

        public void ॱ(final m mVar) {
            this.ˋ.ॱ.ˊ(new Runnable(this) {
                final /* synthetic */ i ˋ;

                public void run() {
                    d dVar = (d) this.ˋ.ˋ.ˊ.remove(mVar.ॱ());
                    if (dVar != null) {
                        dVar.ॱॱ.ॱ().unlinkToDeath(dVar, 0);
                    }
                }
            });
        }

        public void ˊ(String str, IBinder iBinder, Bundle bundle, m mVar) {
            final m mVar2 = mVar;
            final String str2 = str;
            final IBinder iBinder2 = iBinder;
            final Bundle bundle2 = bundle;
            this.ˋ.ॱ.ˊ(new Runnable(this) {
                final /* synthetic */ i ˋ;

                public void run() {
                    d dVar = (d) this.ˋ.ˋ.ˊ.get(mVar2.ॱ());
                    if (dVar == null) {
                        Log.w("MBServiceCompat", "addSubscription for callback that isn't registered id=" + str2);
                    } else {
                        this.ˋ.ˋ.ˏ(str2, dVar, iBinder2, bundle2);
                    }
                }
            });
        }

        public void ॱ(final String str, final IBinder iBinder, final m mVar) {
            this.ˋ.ॱ.ˊ(new Runnable(this) {
                final /* synthetic */ i ˎ;

                public void run() {
                    d dVar = (d) this.ˎ.ˋ.ˊ.get(mVar.ॱ());
                    if (dVar == null) {
                        Log.w("MBServiceCompat", "removeSubscription for callback that isn't registered id=" + str);
                    } else if (!this.ˎ.ˋ.ˎ(str, dVar, iBinder)) {
                        Log.w("MBServiceCompat", "removeSubscription called for " + str + " which is not subscribed");
                    }
                }
            });
        }

        public void ॱ(final String str, final ResultReceiver resultReceiver, final m mVar) {
            if (!TextUtils.isEmpty(str) && resultReceiver != null) {
                this.ˋ.ॱ.ˊ(new Runnable(this) {
                    final /* synthetic */ i ˊ;

                    public void run() {
                        d dVar = (d) this.ˊ.ˋ.ˊ.get(mVar.ॱ());
                        if (dVar == null) {
                            Log.w("MBServiceCompat", "getMediaItem for callback that isn't registered id=" + str);
                        } else {
                            this.ˊ.ˋ.ˎ(str, dVar, resultReceiver);
                        }
                    }
                });
            }
        }

        public void ˎ(m mVar, String str, int i, int i2, Bundle bundle) {
            final m mVar2 = mVar;
            final String str2 = str;
            final int i3 = i;
            final int i4 = i2;
            final Bundle bundle2 = bundle;
            this.ˋ.ॱ.ˊ(new Runnable(this) {
                final /* synthetic */ i ᐝ;

                public void run() {
                    IBinder ॱ = mVar2.ॱ();
                    this.ᐝ.ˋ.ˊ.remove(ॱ);
                    DeathRecipient dVar = new d(this.ᐝ.ˋ, str2, i3, i4, bundle2, mVar2);
                    this.ᐝ.ˋ.ˊ.put(ॱ, dVar);
                    try {
                        ॱ.linkToDeath(dVar, 0);
                    } catch (RemoteException e) {
                        Log.w("MBServiceCompat", "IBinder is already dead.");
                    }
                }
            });
        }

        public void ˋ(final m mVar) {
            this.ˋ.ॱ.ˊ(new Runnable(this) {
                final /* synthetic */ i ˊ;

                public void run() {
                    IBinder ॱ = mVar.ॱ();
                    d dVar = (d) this.ˊ.ˋ.ˊ.remove(ॱ);
                    if (dVar != null) {
                        ॱ.unlinkToDeath(dVar, 0);
                    }
                }
            });
        }

        public void ˏ(String str, Bundle bundle, ResultReceiver resultReceiver, m mVar) {
            if (!TextUtils.isEmpty(str) && resultReceiver != null) {
                final m mVar2 = mVar;
                final String str2 = str;
                final Bundle bundle2 = bundle;
                final ResultReceiver resultReceiver2 = resultReceiver;
                this.ˋ.ॱ.ˊ(new Runnable(this) {
                    final /* synthetic */ i ˏ;

                    public void run() {
                        d dVar = (d) this.ˏ.ˋ.ˊ.get(mVar2.ॱ());
                        if (dVar == null) {
                            Log.w("MBServiceCompat", "search for callback that isn't registered query=" + str2);
                        } else {
                            this.ˏ.ˋ.ˎ(str2, bundle2, dVar, resultReceiver2);
                        }
                    }
                });
            }
        }

        public void ॱ(String str, Bundle bundle, ResultReceiver resultReceiver, m mVar) {
            if (!TextUtils.isEmpty(str) && resultReceiver != null) {
                final m mVar2 = mVar;
                final String str2 = str;
                final Bundle bundle2 = bundle;
                final ResultReceiver resultReceiver2 = resultReceiver;
                this.ˋ.ॱ.ˊ(new Runnable(this) {
                    final /* synthetic */ i ˏ;

                    public void run() {
                        d dVar = (d) this.ˏ.ˋ.ˊ.get(mVar2.ॱ());
                        if (dVar == null) {
                            Log.w("MBServiceCompat", "sendCustomAction for callback that isn't registered action=" + str2 + ", extras=" + bundle2);
                        } else {
                            this.ˏ.ˋ.ॱ(str2, bundle2, dVar, resultReceiver2);
                        }
                    }
                });
            }
        }
    }

    @RequiresApi(28)
    class j extends g {
        final /* synthetic */ MediaBrowserServiceCompat ॱॱ;

        j(MediaBrowserServiceCompat mediaBrowserServiceCompat) {
            this.ॱॱ = mediaBrowserServiceCompat;
            super(mediaBrowserServiceCompat);
        }

        public o.lp.d ॱ() {
            if (this.ॱॱ.ˋ != null) {
                return this.ॱॱ.ˋ.ॱ;
            }
            return new o.lp.d(((MediaBrowserService) this.ˎ).getCurrentBrowserInfo());
        }
    }

    interface m {
        void ˊ(String str, List<MediaItem> list, Bundle bundle, Bundle bundle2) throws RemoteException;

        void ˎ(String str, Token token, Bundle bundle) throws RemoteException;

        void ˏ() throws RemoteException;

        IBinder ॱ();
    }

    static class n implements m {
        final Messenger ˎ;

        n(Messenger messenger) {
            this.ˎ = messenger;
        }

        public IBinder ॱ() {
            return this.ˎ.getBinder();
        }

        public void ˎ(String str, Token token, Bundle bundle) throws RemoteException {
            if (bundle == null) {
                bundle = new Bundle();
            }
            bundle.putInt("extra_service_version", 2);
            Bundle bundle2 = new Bundle();
            bundle2.putString("data_media_item_id", str);
            bundle2.putParcelable("data_media_session_token", token);
            bundle2.putBundle("data_root_hints", bundle);
            ˋ(1, bundle2);
        }

        public void ˏ() throws RemoteException {
            ˋ(2, null);
        }

        public void ˊ(String str, List<MediaItem> list, Bundle bundle, Bundle bundle2) throws RemoteException {
            Bundle bundle3 = new Bundle();
            bundle3.putString("data_media_item_id", str);
            bundle3.putBundle("data_options", bundle);
            bundle3.putBundle("data_notify_children_changed_options", bundle2);
            if (list != null) {
                String str2 = "data_media_item_list";
                if (list instanceof ArrayList) {
                    list = (ArrayList) list;
                } else {
                    Object arrayList = new ArrayList(list);
                }
                bundle3.putParcelableArrayList(str2, list);
            }
            ˋ(3, bundle3);
        }

        private void ˋ(int i, Bundle bundle) throws RemoteException {
            Message obtain = Message.obtain();
            obtain.what = i;
            obtain.arg1 = 2;
            obtain.setData(bundle);
            this.ˎ.send(obtain);
        }
    }

    @Nullable
    public abstract a onGetRoot(@NonNull String str, int i, @Nullable Bundle bundle);

    public abstract void onLoadChildren(@NonNull String str, @NonNull h<List<MediaItem>> hVar);

    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY})
    public void attachToBaseContext(Context context) {
        attachBaseContext(context);
    }

    public void onCreate() {
        super.onCreate();
        if (VERSION.SDK_INT >= 28) {
            this.ᐝ = new j(this);
        } else if (VERSION.SDK_INT >= 26) {
            this.ᐝ = new g(this);
        } else if (VERSION.SDK_INT >= 23) {
            this.ᐝ = new c(this);
        } else if (VERSION.SDK_INT >= 21) {
            this.ᐝ = new b(this);
        } else {
            this.ᐝ = new f(this);
        }
        this.ᐝ.ˎ();
    }

    public IBinder onBind(Intent intent) {
        return this.ᐝ.ˏ(intent);
    }

    public void dump(FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
    }

    public void onLoadChildren(@NonNull String str, @NonNull h<List<MediaItem>> hVar, @NonNull Bundle bundle) {
        hVar.ˊ(1);
        onLoadChildren(str, hVar);
    }

    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY_GROUP})
    public void onSubscribe(String str, Bundle bundle) {
    }

    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY_GROUP})
    public void onUnsubscribe(String str) {
    }

    public void onLoadItem(String str, @NonNull h<MediaItem> hVar) {
        hVar.ˊ(2);
        hVar.ˋ(null);
    }

    public void onSearch(@NonNull String str, Bundle bundle, @NonNull h<List<MediaItem>> hVar) {
        hVar.ˊ(4);
        hVar.ˋ(null);
    }

    public void onCustomAction(@NonNull String str, Bundle bundle, @NonNull h<Bundle> hVar) {
        hVar.ˋ(null);
    }

    public void setSessionToken(Token token) {
        if (token == null) {
            throw new IllegalArgumentException("Session token may not be null.");
        } else if (this.ˎ != null) {
            throw new IllegalStateException("The session token has already been set.");
        } else {
            this.ˎ = token;
            this.ᐝ.ˋ(token);
        }
    }

    @Nullable
    public Token getSessionToken() {
        return this.ˎ;
    }

    public final Bundle getBrowserRootHints() {
        return this.ᐝ.ˊ();
    }

    @NonNull
    public final o.lp.d getCurrentBrowserInfo() {
        return this.ᐝ.ॱ();
    }

    public void notifyChildrenChanged(@NonNull String str) {
        if (str == null) {
            throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged");
        }
        this.ᐝ.ˋ(str, null);
    }

    public void notifyChildrenChanged(@NonNull String str, @NonNull Bundle bundle) {
        if (str == null) {
            throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged");
        } else if (bundle == null) {
            throw new IllegalArgumentException("options cannot be null in notifyChildrenChanged");
        } else {
            this.ᐝ.ˋ(str, bundle);
        }
    }

    @RestrictTo({androidx.annotation.RestrictTo.d.LIBRARY_GROUP})
    public void notifyChildrenChanged(@NonNull o.lp.d dVar, @NonNull String str, @NonNull Bundle bundle) {
        if (dVar == null) {
            throw new IllegalArgumentException("remoteUserInfo cannot be null in notifyChildrenChanged");
        } else if (str == null) {
            throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged");
        } else if (bundle == null) {
            throw new IllegalArgumentException("options cannot be null in notifyChildrenChanged");
        } else {
            this.ᐝ.ˏ(dVar, str, bundle);
        }
    }

    boolean ˋ(String str, int i) {
        if (str == null) {
            return false;
        }
        for (String equals : getPackageManager().getPackagesForUid(i)) {
            if (equals.equals(str)) {
                return true;
            }
        }
        return false;
    }

    void ˏ(String str, d dVar, IBinder iBinder, Bundle bundle) {
        List list = (List) dVar.ʻ.get(str);
        List arrayList;
        if (list == null) {
            arrayList = new ArrayList();
        } else {
            arrayList = list;
        }
        for (he heVar : r1) {
            if (iBinder == heVar.ˎ && ln.ॱ(bundle, (Bundle) heVar.ˏ)) {
                return;
            }
        }
        r1.add(new he(iBinder, bundle));
        dVar.ʻ.put(str, r1);
        ˊ(str, dVar, bundle, null);
        this.ˋ = dVar;
        onSubscribe(str, bundle);
        this.ˋ = null;
    }

    boolean ˎ(String str, d dVar, IBinder iBinder) {
        boolean z = false;
        if (iBinder == null) {
            try {
                boolean z2;
                if (dVar.ʻ.remove(str) != null) {
                    z2 = true;
                } else {
                    z2 = false;
                }
                this.ˋ = dVar;
                onUnsubscribe(str);
                this.ˋ = null;
                return z2;
            } catch (Throwable th) {
                this.ˋ = dVar;
                onUnsubscribe(str);
                this.ˋ = null;
            }
        } else {
            List list = (List) dVar.ʻ.get(str);
            if (list != null) {
                Iterator it = list.iterator();
                boolean z3 = false;
                while (it.hasNext()) {
                    if (iBinder == ((he) it.next()).ˎ) {
                        it.remove();
                        z3 = true;
                    }
                }
                if (list.size() == 0) {
                    dVar.ʻ.remove(str);
                }
                z = z3;
            }
            this.ˋ = dVar;
            onUnsubscribe(str);
            this.ˋ = null;
            return z;
        }
    }

    void ˊ(String str, d dVar, Bundle bundle, Bundle bundle2) {
        final d dVar2 = dVar;
        final String str2 = str;
        final Bundle bundle3 = bundle;
        final Bundle bundle4 = bundle2;
        h anonymousClass1 = new h<List<MediaItem>>(this, str) {
            final /* synthetic */ MediaBrowserServiceCompat ˎ;

            /* synthetic */ void ॱ(Object obj) {
                ˎ((List) obj);
            }

            void ˎ(List<MediaItem> list) {
                if (this.ˎ.ˊ.get(dVar2.ॱॱ.ॱ()) == dVar2) {
                    if ((ˎ() & 1) != 0) {
                        list = this.ˎ.ॱ(list, bundle3);
                    }
                    try {
                        dVar2.ॱॱ.ˊ(str2, list, bundle3, bundle4);
                    } catch (RemoteException e) {
                        Log.w("MBServiceCompat", "Calling onLoadChildren() failed for id=" + str2 + " package=" + dVar2.ˎ);
                    }
                } else if (MediaBrowserServiceCompat.ˏ) {
                    Log.d("MBServiceCompat", "Not sending onLoadChildren result for connection that has been disconnected. pkg=" + dVar2.ˎ + " id=" + str2);
                }
            }
        };
        this.ˋ = dVar;
        if (bundle == null) {
            onLoadChildren(str, anonymousClass1);
        } else {
            onLoadChildren(str, anonymousClass1, bundle);
        }
        this.ˋ = null;
        if (!anonymousClass1.ॱ()) {
            throw new IllegalStateException("onLoadChildren must call detach() or sendResult() before returning for package=" + dVar.ˎ + " id=" + str);
        }
    }

    List<MediaItem> ॱ(List<MediaItem> list, Bundle bundle) {
        if (list == null) {
            return null;
        }
        int i = bundle.getInt("android.media.browse.extra.PAGE", -1);
        int i2 = bundle.getInt("android.media.browse.extra.PAGE_SIZE", -1);
        if (i == -1 && i2 == -1) {
            return list;
        }
        int i3 = i2 * i;
        int i4 = i3 + i2;
        if (i < 0 || i2 < 1 || i3 >= list.size()) {
            return Collections.emptyList();
        }
        if (i4 > list.size()) {
            i4 = list.size();
        }
        return list.subList(i3, i4);
    }

    void ˎ(String str, d dVar, final ResultReceiver resultReceiver) {
        h anonymousClass3 = new h<MediaItem>(this, str) {
            final /* synthetic */ MediaBrowserServiceCompat ॱ;

            /* synthetic */ void ॱ(Object obj) {
                ˊ((MediaItem) obj);
            }

            void ˊ(MediaItem mediaItem) {
                if ((ˎ() & 2) != 0) {
                    resultReceiver.ˊ(-1, null);
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putParcelable(MediaBrowserServiceCompat.KEY_MEDIA_ITEM, mediaItem);
                resultReceiver.ˊ(0, bundle);
            }
        };
        this.ˋ = dVar;
        onLoadItem(str, anonymousClass3);
        this.ˋ = null;
        if (!anonymousClass3.ॱ()) {
            throw new IllegalStateException("onLoadItem must call detach() or sendResult() before returning for id=" + str);
        }
    }

    void ˎ(String str, Bundle bundle, d dVar, final ResultReceiver resultReceiver) {
        h anonymousClass5 = new h<List<MediaItem>>(this, str) {
            final /* synthetic */ MediaBrowserServiceCompat ˎ;

            void ॱ(List<MediaItem> list) {
                if ((ˎ() & 4) != 0 || list == null) {
                    resultReceiver.ˊ(-1, null);
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putParcelableArray(MediaBrowserServiceCompat.KEY_SEARCH_RESULTS, (Parcelable[]) list.toArray(new MediaItem[0]));
                resultReceiver.ˊ(0, bundle);
            }
        };
        this.ˋ = dVar;
        onSearch(str, bundle, anonymousClass5);
        this.ˋ = null;
        if (!anonymousClass5.ॱ()) {
            throw new IllegalStateException("onSearch must call detach() or sendResult() before returning for query=" + str);
        }
    }

    void ॱ(String str, Bundle bundle, d dVar, final ResultReceiver resultReceiver) {
        h anonymousClass4 = new h<Bundle>(this, str) {
            final /* synthetic */ MediaBrowserServiceCompat ˏ;

            /* synthetic */ void ॱ(Object obj) {
                ˏ((Bundle) obj);
            }

            void ˏ(Bundle bundle) {
                resultReceiver.ˊ(0, bundle);
            }

            void ॱ(Bundle bundle) {
                resultReceiver.ˊ(-1, bundle);
            }
        };
        this.ˋ = dVar;
        onCustomAction(str, bundle, anonymousClass4);
        this.ˋ = null;
        if (!anonymousClass4.ॱ()) {
            throw new IllegalStateException("onCustomAction must call detach() or sendResult() or sendError() before returning for action=" + str + " extras=" + bundle);
        }
    }
}
